package com.txd.mofa.login;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.kongzue.baseframework.interfaces.Layout;
import com.kongzue.baseframework.util.JumpParameter;
import com.kongzue.baseframework.util.Preferences;
import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.ResponseListener;
import com.kongzue.baseokhttp.util.Parameter;
import com.ninetaildemonfox.zdl.ninetails.map.JSONUtils;
import com.txd.mofa.MainActivity;
import com.txd.mofa.R;
import com.txd.mofa.base.BaseAty;
import com.txd.mofa.net.NetUtils;
import com.txd.mofa.utils.VerificationTimer1;
import com.txd.mofa.wode.aty.WebAty;
import com.txd.mofa.wode.aty.WebAty1;

import java.util.Map;

@Layout(R.layout.aty_qidongye)
public class QidongyeAty extends BaseAty {

    private ImageView iv;
    private TextView tv;
    private VerificationTimer1 verificationTimer;
    private String type;
    private String zhi;
    private int anInt;

    @Override
    public void initViews() {
        super.initViews();

        iv = findViewById(R.id.iv);
        tv = findViewById(R.id.tv);

        anInt = Preferences.getInstance().getInt(me, "user2", "bootpage");

        verificationTimer = new VerificationTimer1(5000, 1000, tv, new VerificationTimer1.Dianji() {
            @Override
            public void tiaoguo() {
                if (Preferences.getInstance().getInt(me,"tongyi","tongyi") != 1){
//                    jump(XieyiZhengceAty.class,new JumpParameter().put("first","111").put("pos",0));
                    jump(LoginAty.class);
                }else {
                    if (token != null && !token.equals("")) {
                        startActivity(new Intent(QidongyeAty.this, MainActivity.class));
                    } else {
                        startActivity(new Intent(QidongyeAty.this, LoginAty.class));//login
                    }
                }
                finish();
            }
        });
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }


    @Override
    public void initDatas(JumpParameter paramer) {


        String url = paramer.getString("url");

        zhi = Preferences.getInstance().getString(me, "zhi", "zhi");

        Glide.with(me).load(Preferences.getInstance().getString(me, "url", "url")).into(iv);

        verificationTimer.start();
    }

    @Override
    public void setEvents() {

        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump(WebAty1.class, new JumpParameter().put("id", zhi));
                finish();
            }
        });
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Preferences.getInstance().getInt(me,"tongyi","tongyi") != 1){
                    jump(LoginAty.class);
//                    jump(XieyiZhengceAty.class,new JumpParameter().put("first","111").put("pos",0));
                }else {
                    if (token != null && !token.equals("")) {
                        startActivity(new Intent(QidongyeAty.this, MainActivity.class));
                    } else {
                        startActivity(new Intent(QidongyeAty.this, LoginAty.class));//login
                    }
                }
                finish();
            }
        });

    }

    @Override
    protected void onDestroy() {
        if (verificationTimer != null) {
            verificationTimer.cancel();
        }
        super.onDestroy();

    }
}
